package top.jiangqiang.consumer;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class TestController {

    private final RestTemplate restTemplate;
    private final FeignService feignService;

    /**
     * 使用RestTemplate实例进行远程调用
     * @return
     */
    @RequestMapping(value = "/getPort1")
    public String getPort1() {
        return "RestTemplate:" + restTemplate.getForObject("http://service-provider/getPort", String.class);
    }

    /**
     * 使用Fetch进行远程调用
     * @return
     */
    @RequestMapping(value = "/getPort2")
    public String getPort2() {
        return "Feign:" + feignService.getPort();
    }
}